<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/23/023
 * Time: 10:37
 */

namespace app\cms\controller;
use app\api\model\Admin as AdminModel;
use app\lib\exception\AdminException;
use think\Controller;
use app\api\validate\IDMustBePostiveInt;

class Admin extends Controller {

    /**
     * 管理员列表
     * @return \think\response\View
     */
    public function index() {
        $data = AdminModel::getList();
        $this->assign('data', $data);
        return view();
    }

    /**
     * 添加或编辑管理员页面
     * @return \think\response\View
     * @throws AdminException
     */
    public function save_admin() {
        $data = [];
        if (input('?param.id')) {
            (new IDMustBePostiveInt())->goCheck();
            $id = input('param.id');
            $data = AdminModel::getAdminById($id);
            if (!$data) {
                throw new AdminException();
            }
        }
        $this->assign('data', $data);
        return view();
    }
}